<%--
  Created by IntelliJ IDEA.
  User: 113
  Date: 2020/12/5
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<body STYLE="background: #4e555b">
<%
    //加载驱动
    Class.forName("com.mysql.jdbc.Driver");

    //建立数据库连接
    String url="jdbc:mysql://localhost:3306/book";//数据库连接地址
    Connection connection=DriverManager.getConnection(url,"root","root");

    String sql="delete  from gwy where id=?";//在PreparedStatement中使用问号代替实际参数
    PreparedStatement ps=connection.prepareStatement(sql);

    int id= Integer.parseInt(request.getParameter("id"));

    ps.setInt(1,id);

    int count=ps.executeUpdate();

    if (count>0){
        out.print("删除成功");
    }else{
        out.print("删除失败");
    }
    response.setHeader("refresh","1;url=top.jsp");
%>
</body>
